- layout :
-
large_read_area
HAL DTS initialization and configuration functions migration ¶
The goal of this page is to show how to migrate the initialization sequence using STM32CubeMX2:
Open STM32CubeMX2 DTS configuration panel.
Configure the SW layer HAL.
Configure the DTS main features.
Configure the NVIC if the application requires the DTS to be used in IT mode.
Generate the code.
HAL DTS configuration panel ¶
Create a new project with the STM32CubeMX2, then start the initialization and the main configuration.
HAL DTS main features configuration ¶
Configure the DTS main features.
NVIC configuration ¶
Configure the NVIC in case of an interrupt.
Generated DTS initialization and de-initialization sequences ¶
The DTS initialization and de-initialization sequences are generated in the
mx_dts_init
function in
mx_dts.c
file under
$YOUR_PROJECT_NAME$/$YOUR_PROJECT_NAME$_SW/generated/STM32Cube_CodeGen.
Related concepts:
|
Topic |
HAL1 code snippet |
HAL2 code snippet |
|---|---|---|
|
Handle declaration |
DTS_HandleTypeDef hdts;
|
static hal_dts_handle_t hDTS;
|
|
Initialization and configuration sequence |
static void MX_DTS_Init(void)
{
hdts.Instance = DTS;
hdts.Init.QuickMeasure = DTS_QUICKMEAS_DISABLE;
hdts.Init.RefClock = DTS_REFCLKSEL_PCLK;
hdts.Init.TriggerInput = DTS_TRIGGER_HW_NONE;
hdts.Init.SamplingTime = DTS_SMP_TIME_1_CYCLE;
hdts.Init.Divider = 0;
hdts.Init.HighThreshold= 100;
hdts.Init.LowThreshold = 10;
if (HAL_DTS_Init(&hdts) != HAL_OK)
{
Error_Handler();
}
void HAL_DTS_MspInit(DTS_HandleTypeDef *hdts)
{
if (hdts->Instance == DTS)
{
__HAL_RCC_DTS_CLK_ENABLE();
HAL_NVIC_SetPriority(DTS_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DTS_IRQn);
}
}
|
hal_dts_handle_t *mx_dts_init(void)
{
hal_dts_config_t p_config;
if (HAL_DTS_Init(&hDTS, HAL_DTS) != HAL_OK)
{
return NULL;
}
HAL_RCC_DTS_EnableClock();
p_config.reference_clock = HAL_DTS_REFERENCE_CLOCK_PCLK;
if (HAL_DTS_SetConfig(&hDTS, &p_config) != HAL_OK)
{
return NULL;
}
hal_dts_sensor_config_t p_sensor_config;
p_sensor_config.trigger = HAL_DTS_TRIGGER_SOFTWARE;
p_sensor_config.sampling_time = HAL_DTS_SAMPLING_TIME_1_CYCLE;
if (HAL_DTS_SetConfigSensor(&hDTS, HAL_DTS_SENSOR_1, &p_sensor_config) != HAL_OK)
{
return NULL;
}
/* DTS NVIC Configuration ****************************************************************************************/
HAL_CORTEX_NVIC_SetPriority(DTS_IRQn, HAL_CORTEX_NVIC_PREEMP_PRIORITY_0, HAL_CORTEX_NVIC_SUB_PRIORITY_0);
HAL_CORTEX_NVIC_EnableIRQ(DTS_IRQn);
return &hDTS;
}
hal_dts_handle_t *mx_dts_gethandle(void)
{
return &hDTS;
}
|
|
Deinitialization sequence |
static void MX_DTS_DeInit(void)
{
HAL_DTS_DeInit(&hdts);
}
void HAL_DTS_MspDeInit(DTS_HandleTypeDef* hdts)
{
if(hdts->Instance==DTS)
{
__HAL_RCC_DTS_CLK_DISABLE();
HAL_NVIC_DisableIRQ(DTS_IRQn);
}
|
void mx_dts_deinit(void)
{
/* De-initialize the DTS */
HAL_DTS_DeInit(&hDTS);
/* Disable the DTS interrupt request */
HAL_CORTEX_NVIC_DisableIRQ(DTS_IRQn);
/* Reset the DTS peripheral and disable the clock */
HAL_RCC_DTS_Reset();
HAL_RCC_DTS_DisableClock();
}
|
|
IRQ handle function |
void DTS_IRQHandler(void)
{
HAL_DTS_IRQHandler(&hdts);
}
|
void DTS_IRQHandler(void)
{
HAL_DTS_IRQHandler(&hDTS);
}
|